# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=rhash
pkgname=("lib${pkgbase}" "lib${pkgbase}-devel" "${pkgbase}")
pkgver=1.3.6
pkgrel=1
pkgdesc='Utility for verifying hash sums of files'
url='http://rhash.anz.ru/?l=en'
license=('custom' 'MIT')
arch=('i686' 'x86_64')
source=("https://downloads.sourceforge.net/rhash/rhash-${pkgver}-src.tar.gz"
        001-mingw.patch)
makedepends=('openssl-devel')
sha256sums=('964df972b60569b5cb35ec989ced195ab8ea514fc46a74eab98e86569ffbcf92'
            '0de7aa61dfe43fe7ed453d807c10604e1bcd664867b67b13c46a33efe9bc7480')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _fname in "$@"
  do
    msg2 "Applying ${_fname}"
    patch -Nbp1 -i "${srcdir}"/${_fname}
  done
}

del_file_exists() {
  for _fname in "$@"
  do
    if [ -f $_fname ] || [ -d $_fname ]; then
      rm -rf $_fname
    fi
  done
}
# =========================================== #


prepare() {
  cd ${srcdir}/RHash-${pkgver}
  apply_patch_with_msg \
    001-mingw.patch
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -r "${srcdir}"/RHash-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ./configure --prefix=/usr --sysconfdir=/etc \
     --enable-lib-static --enable-lib-shared
  make 
  make install DESTDIR="${srcdir}/dest" PREFIX="/usr" 
}

check() {
   echo "Skipping make check"
   cd "${srcdir}"/build-${CARCH}
   make test
}

package_librhash() {
  groups=('libraries')
  pkgdesc="LibRHash shared library"
  depends=('libopenssl' 'gcc-libs')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -f usr/bin/*.dll "${pkgdir}/usr/bin"
  cd "${srcdir}"/build-${CARCH}
  # license
  install -Dm644 COPYING "${pkgdir}"/usr/share/licenses/rhash/LICENSE
}

package_librhash-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("librhash=${pkgver}")
  pkgdesc="Headers and static library for LibRHash"

  cd ${srcdir}/dest
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include $pkgdir/usr/
  cp -rf ${srcdir}/dest/usr/lib $pkgdir/usr/
}

package_rhash() {
  depends=("librhash=${pkgver}")
  backup=('etc/rhashrc')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -rf ${srcdir}/dest/usr/bin/* ${pkgdir}/usr/bin/
  rm  -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share/* ${pkgdir}/usr
  cp -rf ${srcdir}/dest/etc ${pkgdir}/etc
}

